﻿using System.Windows;
using System.Windows.Controls;

namespace MetroApp.Web.UserControls
{
    /// <summary>
    /// 按钮附加
    /// </summary>
    public static class AproButton
    {
        //定义附加属性: propa(prop + attach) + tab
        // 1. 声明附加属性
        public static readonly DependencyProperty CornerRadiusProperty =
            DependencyProperty.RegisterAttached(
                "CornerRadius",
                typeof(CornerRadius),
                typeof(AproButton),
                new PropertyMetadata(new CornerRadius(0), OnCornerRadiusChanged));

        // 2. Get/Set 方法
        public static CornerRadius GetCornerRadius(DependencyObject obj)
            => (CornerRadius)obj.GetValue(CornerRadiusProperty);

        public static void SetCornerRadius(DependencyObject obj, CornerRadius value)
            => obj.SetValue(CornerRadiusProperty, value);

        // 3. 属性变化时给按钮打标记，让它自动套用我们的 Style
        private static void OnCornerRadiusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (d is Button btn && btn.Style == null)
            {
                btn.SetResourceReference(FrameworkElement.StyleProperty, typeof(Button));
            }
        }
    }
}
